package com.javaee.xiangyang.util;

import com.javaee.xiangyang.entity.Goods;
import com.javaee.xiangyang.entity.User;

import java.util.Map;

public class SQLProviderUtil {

    /**
     * UserMapper.updateMoneyByUserId语句拼装
     * @param map   键值对  对应接口中条件.  param中里面的值为key ,封装的值为value
     * @return 返回对应拼装好的sql语句
     */
    public String updateMoneyByUserIdUtil(Map<String, Object> map){
        User user = (User) map.get("user");
        boolean type = (boolean) map.get("type");
        String sql = "update user set userMoney = userMoney";
        if (type){
            sql = sql+" + ";
        }else {
            sql = sql+" - ";
        }
        sql= sql + user.getUserMoney() + " where userAccount = "+ user.getUserAccount();
        return sql;
    }

    public String updateInventoryByGoodsId(Map<String, Object> map){
        Goods goods = (Goods)map.get("goods");
        boolean type = (boolean) map.get("type");
        String sql = "update goods set goodsInventory = goodsInventory";
        if (type){
            sql = sql+" + ";
        }else {
            sql = sql+" - ";
        }
        sql= sql + goods.getGoodsInventory() + " where goodsId = "+ goods.getGoodsId();
        return sql;
    }

}
